<!--
 * @Description:键盘keyCode事件
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-07 20:15:36
 -->
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>键盘keyCode事件</title>
	<style>
		#div1 {
			width: 20px;
			height: 20px;
			background: #ccc;
			position: absolute;
		}
	</style>

</head>
<script>
	window.onload = function () {

		document.onkeydown = function (ev) {
			var oDiv = document.getElementsByTagName('div')
			var oEvent = ev || event
			console.log(ev.keyCode)

		}

	}
</script>

<body>
	<div>
		keyCode 键盘事件 获取用户按下的那个键<br>
		onkeydown 按键按下<br>
		onkeyup  按键抬起
	</div>
	<div id="div1"></div>

</body>

</html>